// subpages0/distribPoster/distribPoster.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var that = this;
    if (e && e.enterfrom) {
      var enterfrom = e.enterfrom == 'share' ? true : false;
      that.setData({
        enterfrom: enterfrom
      })
    }
    if(e&&e.id){
      var goodDetail = {
        id:e.id
      }
      that.setData({
        goodDetail: goodDetail,
        goodType: 'good'
      })
    }
    if (e && e.esid) {
      that.setData({
        esid: e.esid
      })
    }
    var res = wx.getSystemInfoSync();
    that.setData({
      winW: res.windowWidth,
      winH: res.windowHeight
    })
    app.setNavtitle("生成海报");
    // app.requestShareinfo(that,'distri');
  
      var pageShare = this.selectComponent('.page-share'), 
      posterData={map:'applet_goods_details_poster',gid:that.data.goodDetail.id,type:'good'};
      console.log(posterData)
      this.setData({
        posterData:posterData
      })
      pageShare.requestShareinfo(posterData)
    
  },
  saveImage:function(){
    var pageShare = this.selectComponent('.page-share');
    pageShare.saveImage()
  },
  onShareAppMessage: function () {
    var that = this;
    var mid = app.globalData.userInfo.mid;
    console.log('mid' + app.globalData.userInfo.mid)
    var goodid = that.data.shareInfo.id;
    var title = that.data.shareInfo.name;
    var cover = that.data.shareImg;
    app.getPoint(that);
    var url = '/pages/goodDetail/goodDetail?enterfrom=share&id=' + goodid + '&mid=' + mid;
    if (that.data.esid){
      url = '/pages/shopgoodsDetail/shopgoodsDetail?id=' + gid + '&mid=' + mid
    }
    return {
      title: title,
      imageUrl: cover,
      path: url
    }
  }
})